<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- <meta http-equiv="refresh" content="10"> -->
<title>美丽敲敲门大地图</title>
<style type="text/css">
html {
	height: 100%
}

body {
	height: 100%;
	margin: 0px;
	padding: 0px
}

#container {
	height: 100%
}
</style>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=DDbl4GuGNmDrLbKeaDsCzAeDfOGhdyET">
	//v2.0版本的引用方式：src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"
	//v1.4版本及以前版本的引用方式：src="http://api.map.baidu.com/api?v=1.4&key=您的密钥&callback=initialize"
</script>
</head>
<script language="javascript">
	var XMLHttpReq;
	//创建XMLHttpRequest对象         
	function createXMLHttpRequest() {
		if (window.XMLHttpRequest) { //Mozilla 浏览器  
			XMLHttpReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE浏览器  
			try {
				XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
				}
			}
		}
	}
</script>
<body>
	<div id="container"></div>
	<script type="text/javascript">
		var map = new BMap.Map("container"); // 创建地图实例  
		map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用
		var point = new BMap.Point(115.851808, 28.694773); // 创建点坐标  
		var point2 = new BMap.Point(115.86999, 28.687675);
		map.centerAndZoom(point, 15); // 初始化地图，设置中心点坐标和地图级别

		//放缩控件
		/* var opts = {
			type : BMAP_NAVIGATION_CONTROL_SMALL
		}
		map.addControl(new BMap.NavigationControl(opts)); */

		//系统图标遮盖
		var marker = new BMap.Marker(point); // 创建标注    
		map.addOverlay(marker); // 将标注添加到地图中

		//创建小狐狸
		var pt = new BMap.Point(115.86999, 28.687675);
		var myIcon = new BMap.Icon(
				"http://developer.baidu.com/map/jsdemo/img/fox.gif",
				new BMap.Size(200, 157));
		var marker2 = new BMap.Marker(pt, {
			icon : myIcon
		}); // 创建标注
		var label = new BMap.Label("我是文字标注哦", {
			offset : new BMap.Size(5, 5)
		});
		marker2.setLabel(label);
		map.addOverlay(marker2); // 将标注添加到地图中

		var mapPoints;
		//查询按钮
		function search() {
			sendRequest();
		}

		//发送请求函数  
		function sendRequest() {
			createXMLHttpRequest();
			var url = "http://localhost/mlqm/map/getbilllocation";
			XMLHttpReq.open("GET", url, true);
			XMLHttpReq.onreadystatechange = processResponse;//指定响应函数  
			XMLHttpReq.send(null); // 发送请求  
		}

		// 处理返回信息函数  
		function processResponse() {
			if (XMLHttpReq.readyState == 4) { // 判断对象状态  
				if (XMLHttpReq.status == 200) { // 信息已经成功返回，开始处理信息
					DisplayHot();
					//setTimeout("sendRequest()", 1000);
				} else { //页面不正常  
					window.alert("您所请求的页面有异常。");
				}
			}
		}

		function DisplayHot() {
			var r = XMLHttpReq.responseText;
			if (r == "") {
				alert("未查找到！！！");
			} else {
				var obj = JSON.parse(r);
				var data = obj.data;
				mapPoints = data;

				//for (var i = 0; i < mapPoints.length; i++) {
				for (var i = 0; i < 10; i++) {
					alert(mapPoints[i].j_longitude+","+mapPoints[i].j_latitude);
					var pp = new BMap.Point(mapPoints[i].j_longitude,
							mapPoints[i].j_latitude); // 创建点坐标
					var ppc = new BMap.Point(mapPoints[i].c_longitude,
							mapPoints[i].c_latitude); // 创建点坐标

					var transit = new BMap.TransitRoute(map, {
						renderOptions : {
							map : map
						}
					});
					
					var driving = new BMap.DrivingRoute(map, {
						renderOptions : {
							map : map,
							//autoViewport : true
						},
						policy:BMAP_DRIVING_POLICY_LEAST_TIME
					});
					//driving.search(pp, ppc);
					transit.search(pp, ppc);
					//alert(pp_address);
					//transit.search("金久国际大厦停车场(西出入口)", "八一广场");
					//transit.search(pp,mapPoints[i].address);
					//driving.search("金久国际大厦停车场(西出入口)",mapPoints[i].address);
					//alert(mapPoints[i].address);
					//transit.search(pp_address, mapPoints[i].address);
					//transit.search(pp_address, mapPoints[i].address);

				}
			}
		}

		search();
	</script>
</body>
</html>